/**
 * 
 */
package controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import model.*;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import service.Userservice;

/**
 * @author james
 *
 */
@Controller
@RequestMapping("/main")
 public class MainController {
	
	@Resource(name="userService")
	private Userservice userservice;
	
	/*	*//**
	 * 提交表单
	 * 
	 * @param admin
	 * @return
	 */
	/*
	 * 
	 * @RequestMapping(method=RequestMethod.POST) public String
	 * admin(@ModelAttribute("admin") String admin){ if(admin == "user"){ return
	 * "main/searchId.do?id=" + 1; } else if(admin == "manager"){ return
	 * "redirect:main/insert.do"; } else{ return "account/fail"; } }
	 */

	/*	*//**
	 * 表单初始化 for insert
	 * 
	 * @param model
	 * @return
	 */
	/*
	 * @RequestMapping(value="/insert.do",method = RequestMethod.GET) public
	 * String initForm(ModelMap model){ //这个是绑定用户输入框的对象 User user = new User();
	 * model.addAttribute("user", user); return "account/insert"; }
	 */

	/*	*//**
	 * 提交表单
	 * 
	 * @param user
	 * @return
	 */
	/*
	 * @RequestMapping(value="/insert.do",method=RequestMethod.POST)//@
	 * RequestMapping(method = RequestMethod.POST)绑定POST表单提交请求 public String
	 * login(@ModelAttribute("user") User user){ //@ModelAttribute("account")
	 * Account account绑定表单对象。 userservice.insert(user.getF_name(),
	 * user.getL_name(),user.getSalary(),user.getEmail()); return
	 * "redirect:all.do"; }
	 */
	
	/**
	 * 初始化
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "admin.do", method = RequestMethod.GET)
	public String findUserid(String id, ModelMap model) {
		model.put("id", id);
		return "account/Reporting_Person";
	}
	
	
	/**
	 * 提交表单Person
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/insertPerson.do",method=RequestMethod.GET)//@RequestMapping(method = RequestMethod.POST)绑定POST表单提交请求
	public String login(HttpServletRequest request){ //@ModelAttribute("account") Account account绑定表单对象。 
		String fname = request.getParameter("fname");
		String lname = request.getParameter("lname");
		String phonetest = request.getParameter("phone");
		System.out.print(phonetest);
		int contact_phone = Integer.parseInt(request.getParameter("phone"));
		String position = request.getParameter("position");
		String contact_email = request.getParameter("email");
		int age = Integer.parseInt(request.getParameter("age"));
		String sex = request.getParameter("sex");
		System.out.print("++");
		
		
 		
		userservice.insert(fname,lname,position,contact_phone,contact_email,age,sex);
			return "account/Reporting_Incident";
	}
	
	/**
	 * insert incident
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/insertIncident.do",method=RequestMethod.GET)
	public String insertIncident(HttpServletRequest request){
		String incidentLoc = request.getParameter("In_loca");
		String des = request.getParameter("G_I_d");
		String intial = request.getParameter("C_i_o");
 		userservice.insertIncident(incidentLoc, des, intial);
		
		return "account/Reporting_Plan";
	}
	/**
	 * insert plan_type
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/insertPlan.do",method=RequestMethod.GET)
 	public String insertPlan(HttpServletRequest request){
		String plan = request.getParameter("P_t");
		String des = request.getParameter("P_d");
 		userservice.insertPlan(plan, des);
		
		return "account/Success";
	}
	
	
	/**
	 * 查看所有用户
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/all.do", method=RequestMethod.GET)
	public String profile(Model model){
 		List<Person> user = userservice.readPerson();
		List<Incident> incident = userservice.readIncident();
		List<FollowPlan> plan = userservice.readPlan();
		
		model.addAttribute("person",user);
		model.addAttribute("incident",incident);
		model.addAttribute("plan",plan);
 		return "account/FindAll";
 	}
	
	/*	*//**
	 * 账户信息
	 * 
	 * @param id
	 * @param model
	 * @return
	 */
	/*
	 * @RequestMapping(value="/searchId.do",method=RequestMethod.GET) public
	 * String profile(@RequestParam("id") int id, ModelMap model){ User user =
	 * userservice.read(id); // String input = user.getF_name();
	 * model.addAttribute("msg", user); // 跳转到用户信息页面 return "account/profile"; }
	 */
	
	


}
